﻿using System.Reflection;

namespace GrainManage.Core.Util
{
    public sealed class Initializor
    {
        public static void Initialize<TEntity, TValue>(TEntity entity, TValue defaultValue)
        {
            var valueType = typeof(TValue);
            var properties = typeof(TEntity).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var item in properties)
            {
                if (item.PropertyType == valueType)
                {
                    if (item.GetValue(entity, null) == null)
                    {
                        item.SetValue(entity, defaultValue, null);
                    }
                }
            }
        }
    }
}
